#include "../Engine/Includes.h"

using namespace Cartesia;


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) 
{
	// TEMPORAL
	static float rot2d = 0.1f;;
	static float rot3d = 0.001f;
	Graphics::Startup(hInstance, 800, 600);
	// TEMPORAL.

	MSG msg;

	if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
	{	
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}


		//##########################################################
		// TEMPORAL

		//this->DrawSquare(-200, 200, 200, -200); // TEMPORAL
		//TEMPORAL
		Time::FirstMeasure();
		Shape s, t;
		Sprite sp, ghost;

		ID3DXMesh * esfera;
		ID3DXMesh * caja;
		ID3DXMesh * cilindro;
		ID3DXMesh * cono;
		ID3DXMesh * tetera;
		ID3DXMesh * toro;
		esfera	= Graphics::CreateSphere(1300, 24, 14);
		caja	= Graphics::CreateBox(900, 2800, 1500);
		cilindro= Graphics::CreateCylinder(1000, 1500, 2500, 20, 10);
		cono	= Graphics::CreateCylinder(1, 500, 2500, 20, 10);
		tetera	= Graphics::CreateTeapot();
		toro	= Graphics::CreateTorus(1500, 500, 12, 30);

		t.SetShape(SHAPE_QUAD);
		t.SetColor(0xffffffff);
		t.SetDim(5,5);
		t.SetPos(0,0);

		s.SetShape(SHAPE_QUAD);
		s.SetColorPerVertex(0xaa004466, 0xff00ffcc, 0xff8800dd, 0x22fffc55);
		//s.SetColor(0xddcccc88);
		s.SetDim(200,200);
		s.SetPos(0, 0);
		s.SetPivot(0.5, 0.5);

		//sp.Load("E:/SVN/Cartesia/Bin/metal.bmp");
		sp.Load("data/metal.jpg");
		//sp.SetPos(0,0);
		sp.SetDim(200,200);
		sp.SetPos(50,0);

		ghost.Load("data/inky.png");
		ghost.SetDim(64, 64);
		ghost.SetPos(150,0);
		ghost.SetPivot(2,0);
		ghost.SetRotation(45.0f);
		ghost.CreateAnimation(130, 16, 16);

		VertexColor _linea[2];
		_linea[0].Set(50,50,1,0xff559900);
		_linea[1].Set(450,150,1,0xff559900);

		// TEMPORAL
		//##########################################################



	while (msg.message != WM_QUIT)
	{
		if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
		{	
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		Graphics::BeginScene();
		Graphics::Clear();

		//##########################################################

		//---------------------------------------------------------
		//*// 2D
		rot2d += 0.1f * Time::GetDeltaT();
		//rot3d += 0.000001f;
		//s.Rotate(rotameElCubo);

		//SHAPES
		//s.Draw();
		//t.Draw();

		//SPRITE
		sp.Rotate(rot2d);
		sp.Draw();

		//SPRITE ANIM
		ghost.UpdateAnimation(15, Time::GetDeltaT());
		ghost.Rotate(rot2d);
		ghost.Draw();

		// LINEA
		//Graphics::LoadIdentity();
		//Graphics::Draw(_linea, D3DPT_LINELIST, 2);
		//*/

		//---------------------------------------------------------
		/*// 3D!!!!
		Graphics::SetProjectionPerspective();
		Graphics::SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

		Graphics::RotateX(rot3d * 24);
		//Graphics::RotateY(rot3d * 2.2f);
		Graphics::RotateZ(rot3d * 12.2f);
		//Graphics::DrawD3DXMesh(esfera);
		//Graphics::DrawD3DXMesh(caja);
		//Graphics::DrawD3DXMesh(cono);
		//Graphics::DrawD3DXMesh(cilindro);
		Graphics::DrawD3DXMesh(tetera);
		//Graphics::DrawD3DXMesh(toro);
		//*/

		//##########################################################

		Graphics::EndScene();
		Graphics::Present();

		Time::Measure();
	}


	return 0;
}

